package com.qdu.bussiness.service.impl;

import java.util.Date;
import java.util.List;

import com.qdu.common.core.domain.AjaxResult;
import com.qdu.common.core.domain.model.LoginUser;
import com.qdu.common.utils.SecurityUtils;
import com.qdu.common.utils.id.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qdu.bussiness.mapper.BusRechargeMapper;
import com.qdu.bussiness.domain.BusRecharge;
import com.qdu.bussiness.service.IBusRechargeService;

/**
 * 充值记录Service业务层处理
 * 
 * @author qdu
 * @date 2022-03-13
 */
@Service
public class BusRechargeServiceImpl implements IBusRechargeService
{
    @Autowired
    private BusRechargeMapper busRechargeMapper;

    /**
     * 查询充值记录
     * 
     * @param rechargeId 充值记录主键
     * @return 充值记录
     */
    @Override
    public BusRecharge selectBusRechargeByRechargeId(Long rechargeId)
    {
        return busRechargeMapper.selectBusRechargeByRechargeId(rechargeId);
    }

    /**
     * 查询充值记录列表
     * 
     * @param busRecharge 充值记录
     * @return 充值记录
     */
    @Override
    public List<BusRecharge> selectBusRechargeList(BusRecharge busRecharge)
    {
        if(!SecurityUtils.getUsername().equals("admin")){
            busRecharge.setRechargeUser(SecurityUtils.getUsername());
        }
        return busRechargeMapper.selectBusRechargeList(busRecharge);
    }

    /**
     * 新增充值记录
     * 
     * @param busRecharge 充值记录
     * @return 结果
     */
    @Override
    public AjaxResult insertBusRecharge(BusRecharge busRecharge)
    {
        busRecharge.setRechargeId(IdUtil.getId());
        busRecharge.setCreateUser(SecurityUtils.getUsername());
        busRecharge.setRechargeTime(new Date());
        int rechargeRes = busRechargeMapper.insertBusRecharge(busRecharge);
        if(rechargeRes < 1) {
            throw new RuntimeException("创建充值记录单失败！");
        }
        return AjaxResult.success();
    }

    /**
     * 修改充值记录
     * 
     * @param busRecharge 充值记录
     * @return 结果
     */
    @Override
    public int updateBusRecharge(BusRecharge busRecharge)
    {
        return busRechargeMapper.updateBusRecharge(busRecharge);
    }

    /**
     * 批量删除充值记录
     * 
     * @param rechargeIds 需要删除的充值记录主键
     * @return 结果
     */
    @Override
    public int deleteBusRechargeByRechargeIds(Long[] rechargeIds)
    {
        return busRechargeMapper.deleteBusRechargeByRechargeIds(rechargeIds);
    }

    /**
     * 删除充值记录信息
     * 
     * @param rechargeId 充值记录主键
     * @return 结果
     */
    @Override
    public int deleteBusRechargeByRechargeId(Long rechargeId)
    {
        return busRechargeMapper.deleteBusRechargeByRechargeId(rechargeId);
    }
}
